package com.burry.ajax.good;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import applelew.util.Debug;

import com.burry.action.BaseAction;
import com.burry.bo.SelectItems;
import com.burry.services.GoodService;

public class GoodAction extends BaseAction{
	
	private String goodId = null;
	private String colorId = null;
	private String num = null;
	private String size = null;
	
	public String getNum() {
		return num;
	}
	public void setNum(String num) {
		this.num = num;
	}
	public String getSize() {
		return size;
	}
	public void setSize(String size) {
		this.size = size;
	}

	private InputStream inputStream;
	public InputStream getInputStream() {
		return inputStream;
	}
	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}
	public String getGoodId() {
		return goodId;
	}
	public void setGoodId(String goodId) {
		this.goodId = goodId;
	}
	public String getColorId() {
		return colorId;
	}
	public void setColorId(String colorId) {
		this.colorId = colorId;
	}
	
	public String getGoodInfo(){
		List t = new ArrayList();
		Map a = new HashMap();
		a.put("one", "1");
		a.put("two", "2");
		t.add(a);
		
		JSONArray json = JSONArray.fromObject(t);
		String allSize = json.toString();

		try {
			setInputStream(new ByteArrayInputStream(allSize.getBytes("utf-8")));
		} catch (UnsupportedEncodingException e) {
			Debug.logError(e.getMessage());
		}
		return SUCCESS;
	}
	
	public String getSelectGood(){
		GoodService gs = new GoodService();
		SelectItems si = gs.getSelectGood(size, num, goodId, colorId);
		JSONObject json = JSONObject.fromObject(si);
		String allSize = json.toString();

		try {
			setInputStream(new ByteArrayInputStream(allSize.getBytes("utf-8")));
		} catch (UnsupportedEncodingException e) {
			Debug.logError(e.getMessage());
		}
		return SUCCESS;
	}
	
	

}
